package com.zzb.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import redis.clients.jedis.Jedis;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ASUS
 */
@Configuration
public class InterceptorConfig implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String path = request.getServletPath();
        if (path.startsWith("/back/")) {
            String loginName = request.getParameter("loginName");
            Jedis jedis = new Jedis("localhost", 6379);
            String username = jedis.get(loginName);
            if (username == null) {
                return false;
            } else {
// 放行
                return true;
            }
        } else {
            return true;
        }
    }
}
